import * as echarts from 'echarts';
import { useEffect, useRef } from 'react';
import { ActiveRingChart } from '@jiaminghi/data-view-react'

function App() {
  var chartDom1 = useRef<HTMLDivElement>(null);
  var chartDom2 = useRef<HTMLDivElement>(null);
  var chartDom3 = useRef<HTMLDivElement>(null);
  var chartDom4 = useRef<HTMLDivElement>(null);
  var chartDom5 = useRef<HTMLDivElement>(null);
  var chartDom6 = useRef<HTMLDivElement>(null);
  var chartDom7 = useRef<HTMLDivElement>(null);
  useEffect(() => {
    if (chartDom1.current) {
      var myChart1 = echarts.init(chartDom1.current);
      var option1;
      option1 = {
        legend: {},
        // tooltip: {},
        dataset: {
          source: [
            ['01', 'NO', 'CO2'],
            ['01', 43.3, 93.7],
            ['03', 83.1, 55.1],
            ['04', 86.4, 82.5],
            ['05', 72.4, 39.1],
            ['06', 86.4, 82.5],
            ['07', 72.4, 39.1]
          ]
        },
        xAxis: { type: 'category' },
        yAxis: {},
        // Declare several bar series, each will be mapped
        // to a column of dataset.source by default.
        series: [{ type: 'bar' }, { type: 'bar' }]
      };
      myChart1.setOption(option1);
    }
  }, [])
  useEffect(() => {
    if (chartDom2.current) {
      var myChart2 = echarts.init(chartDom2.current);
      var option2;
      option2 = {
        radar: {
          shape: 'circle',
          indicator: [
            { name: '一', max: 6500 },
            { name: '日', max: 16000 },
            { name: '六', max: 30000 },
            { name: '五', max: 38000 },
            { name: '四', max: 52000 },
            { name: '三', max: 25000 },
            { name: '二', max: 15000 },
          ]
        },
        series: [
          {
            name: 'Budget vs spending',
            type: 'radar',
            data: [
              {
                value: [4200, 3000, 20000, 35000, 50000, 18000],
                name: 'Allocated Budget'
              },
              {
                value: [5000, 14000, 28000, 26000, 42000, 21000],
                name: 'Actual Spending'
              },
              {
                value: [3000, 2000, 30000, 4000, 6000, 5000],
                name: 'Allocated'
              },
            ]
          }
        ]
      };
      myChart2.setOption(option2);
    }
  }, [])
  useEffect(() => {
    if (chartDom3.current) {
      var myChart3 = echarts.init(chartDom3.current);
      var option3;
      option3 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#orange'
            }
          }
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['01', '02', '03', '04', '05', '06', '07']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'Video Ads',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            color: [
              'gold',
            ],
            data: [150, 232, 201, 154, 190, 330, 410]
          },
        ]
      };
      myChart3.setOption(option3);
    }
  }, [])
  useEffect(() => {
    if (chartDom4.current) {
      var myChart4 = echarts.init(chartDom4.current);
      var option4;
      option4 = {
        dataset: [
          {
            source: [
              ['Product', 'Sales', 'Price', 'Year'],

              ['Cake', 123, 32, 2011],
              ['Cereal', 231, 14, 2011],
              ['Tofu', 235, 5, 2011],

              ['Cake', 143, 30, 2012],
              ['Cereal', 201, 19, 2012],
              ['Tofu', 255, 7, 2012],

              ['Cake', 153, 28, 2013],
              ['Cereal', 181, 21, 2013],
              ['Tofu', 395, 4, 2013],

              ['Cake', 223, 29, 2014],
              ['Cereal', 211, 17, 2014],
              ['Tofu', 345, 3, 2014],
            ]
          },
          {
            transform: {
              type: 'filter',
              config: { dimension: 'Year', value: 2011 }
            }
          },
          {
            transform: {
              type: 'filter',
              config: { dimension: 'Year', value: 2012 }
            }
          },
          {
            transform: {
              type: 'filter',
              config: { dimension: 'Year', value: 2013 }
            }
          }
        ],
        series: [
          {
            type: 'pie',
            radius: 50,
            center: ['50%', '25%'],
            datasetIndex: 1
          },
          {
            type: 'pie',
            radius: 50,
            center: ['50%', '50%'],
            datasetIndex: 2
          },
          {
            type: 'pie',
            radius: 50,
            center: ['50%', '75%'],
            datasetIndex: 3
          }
        ],
        // Optional. Only for responsive layout:  
        media: [
          {
            query: { minAspectRatio: 1 },
            option: {
              series: [
                { center: ['25%', '50%'] },
                { center: ['50%', '50%'] },
                { center: ['75%', '50%'] }
              ]
            }
          },
          {
            option: {
              series: [
                { center: ['50%', '25%'] },
                { center: ['50%', '50%'] },
                { center: ['50%', '75%'] }
              ]
            }
          }
        ]
      };
      myChart4.setOption(option4);
    }
  }, [])
  useEffect(() => {
    if (chartDom5.current) {
      var myChart5 = echarts.init(chartDom5.current);
      var option5;
      option5 = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [120, 100, 150, 80, 70, 110, 130],
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            },
            color: [
              '#25cccc',
            ],
          }
        ]
      };
      myChart5.setOption(option5);
    }
  }, [])
  useEffect(() => {
    if (chartDom6.current) {
      var myChart6 = echarts.init(chartDom6.current);
      var option6;
      option6 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: [
          {
            type: 'category',
            data: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            data: [50, 52, 100, 120, 140, 130, 120, 40, 52, 100, 134, 140, 130, 120, 30, 52, 30],
            color: [
              '#25cccc',
            ],
          }
        ]
      };
      myChart6.setOption(option6);
    }
  }, [])
  const config = {
    data: [
      {
        name: '二氧化碳',
        value: 35.72,
      },
      {
        name: '氮气',
        value: 35.26
      },
      {
        name: '氧气',
        value: 35.49
      },
    ]
  }
  useEffect(() => {
    if (chartDom7.current) {
      var myChart7 = echarts.init(chartDom7.current);
      var option7;
      const data = [
        [
          [28604, 77, 17096869, 'Australia', 1990],
          [31163, 77.4, 27662440, 'Canada', 1990],
          [1516, 68, 11546573, 'China', 1990],
          [13670, 74.7, 10582082, 'Cuba', 1990],
          [28599, 75, 4986705, 'Finland', 1990],
          [29476, 77.1, 56943299, 'France', 1990],
          [31476, 75.4, 78958237, 'Germany', 1990],
          [28666, 78.1, 254830, 'Iceland', 1990],
          [1777, 57.7, 87060776, 'India', 1990],
          [29550, 79.1, 122249285, 'Japan', 1990],
          [2076, 67.9, 20194354, 'North Korea', 1990],
          [12087, 72, 42972254, 'South Korea', 1990],
          [24021, 75.4, 3397534, 'New Zealand', 1990],
          [43296, 76.8, 4240375, 'Norway', 1990],
          [10088, 70.8, 38195258, 'Poland', 1990],
          [19349, 69.6, 147568552, 'Russia', 1990],
          [10670, 67.3, 53994605, 'Turkey', 1990],
          [26424, 75.7, 57110117, 'United Kingdom', 1990],
          [37062, 75.4, 252847810, 'United States', 1990]
        ],
        [
          [44056, 81.8, 23968973, 'Australia', 2015],
          [43294, 81.7, 35939927, 'Canada', 2015],
          [13334, 76.9, 137608943, 'China', 2015],
          [21291, 78.5, 11389562, 'Cuba', 2015],
          [38923, 80.8, 5503457, 'Finland', 2015],
          [37599, 81.9, 64395345, 'France', 2015],
          [44053, 81.1, 80688545, 'Germany', 2015],
          [42182, 82.8, 329425, 'Iceland', 2015],
          [5903, 66.8, 131105527, 'India', 2015],
          [36162, 83.5, 126573481, 'Japan', 2015],
          [1390, 71.4, 25155317, 'North Korea', 2015],
          [34644, 80.7, 50293439, 'South Korea', 2015],
          [34186, 80.6, 4528526, 'New Zealand', 2015],
          [64304, 81.6, 5210967, 'Norway', 2015],
          [24787, 77.3, 38611794, 'Poland', 2015],
          [23038, 73.13, 143456918, 'Russia', 2015],
          [19360, 76.5, 78665830, 'Turkey', 2015],
          [38225, 81.4, 64715810, 'United Kingdom', 2015],
          [53354, 79.1, 321773631, 'United States', 2015]
        ]
      ];
      option7 = {
        xAxis: {
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          }
        },
        yAxis: {
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          },
          scale: true
        },
        series: [
          {
            name: '1990',
            data: data[0],
            type: 'scatter',
            symbolSize: function (data) {
              return Math.sqrt(data[2]) / 5e2;
            },
            emphasis: {
              focus: 'series',
              label: {
                show: true,
                formatter: function (param) {
                  return param.data[3];
                },
                position: 'top'
              }
            },
            itemStyle: {
              shadowBlur: 10,
              shadowColor: 'rgba(120, 36, 50, 0.5)',
              shadowOffsetY: 5,
            }
          },
          {
            name: '2015',
            data: data[1],
            type: 'scatter',
            symbolSize: function (data) {
              return Math.sqrt(data[2]) / 5e2;
            },
            emphasis: {
              focus: 'series',
              label: {
                show: true,
                formatter: function (param) {
                  return param.data[3];
                },
                position: 'top'
              }
            },
            itemStyle: {
              shadowBlur: 10,
              shadowColor: 'rgba(25, 100, 150, 0.5)',
              shadowOffsetY: 5,

            }
          }
        ]
      };
      myChart7.setOption(option7);
    }
  }, [])
  return (
    <div className="index">
      <header>
        <h2>空气质量可视化检测平台</h2>
        <span>202.02.13  12:23:39</span>
      </header>
      <div className="div">
        <div className="left">
          <div className="div1">
            <h3>名区域污染趋势_日</h3>
            <div ref={chartDom1} style={{ width: '100%', height: '300px' }} />
          </div>
          <div className="div2">
            <h3>污染指标占比_周</h3>
            <div ref={chartDom2} style={{ width: '210px', height: '220px' }} />
            <div className='div2-2'>
              <p>
                <span className='s1'>CO2</span>
                <span className='s2'>2300T</span>
              </p>
              <p>
                <span className='s1'>CO</span>
                <span className='s3'>1300T</span>
              </p>
              <p>
                <span className='s1'>NO</span>
                <span className='s4'>1300T</span>
              </p>
            </div>
          </div>
          <div className="div3">
            <h3>近7日数变化</h3>
            <div ref={chartDom3} style={{ width: '100%', height: '300px' }} />
          </div>
        </div>
        <div className="center">
          <div className="div1">
            <h3>空气质量情况</h3>
            <div ref={chartDom4} style={{ width: '100%', height: '300px' }} />
          </div>
          <div className="div2">
            <div ref={chartDom5} style={{ width: '100%', height: '200px' }} />
          </div>
          <div className="div3">
            <h3>区域实时污染测</h3>
            <p>
              <span className='s1'>类型</span>
              <span className='s1'>监测点</span>
              <span className='s1'>检测值</span>
              <span className='s1'>日均值</span>
              <span className='s1'>峰值</span>
              <span className='s1'>操作</span>
            </p>
            <p>
              <span className='s1'>XXX区域</span>
              <span>点1</span>
              <span>120</span>
              <span>150</span>
              <span>130</span>
              <span>定位</span>
            </p>
            <p>
              <span className='s1'>XXX区域</span>
              <span>点2</span>
              <span>300</span>
              <span>200</span>
              <span>200</span>
              <span>定位</span>
            </p>
            <p>
              <span className='s1'>XXX区域</span>
              <span>点2</span>
              <span>300</span>
              <span>200</span>
              <span>200</span>
              <span>定位</span>
            </p>
            <p>
              <span className='s1'>XXX区域</span>
              <span>点2</span>
              <span>300</span>
              <span>200</span>
              <span>200</span>
              <span>定位</span>
            </p>
            <p>
              <span className='s1'>XXX区域</span>
              <span>点3</span>
              <span>130</span>
              <span>300</span>
              <span>120</span>
              <span>定位</span>
            </p>
          </div>
        </div>
        <div className="right">
          <div className="div1">
            <h3>空气指标 ( AQI ) </h3>
            <div ref={chartDom6} style={{ width: '100%', height: '300px' }} />
          </div>
          <div className="div2">
            <h3>超标次数监测 </h3>
            <ActiveRingChart config={config} style={{ width: '300px', height: '300px', }} className="div2-1" />
            <div className='div2-2'>
              <p>
                <span className='s1'>二氧化碳</span>
                <span className='s2'>35.72%</span>
              </p>
              <p>
                <span className='s1'>氮气</span>
                <span className='s3'>35.26%</span>
              </p>
              <p>
                <span className='s1'>氧气</span>
                <span className='s4'>35.49%</span>
              </p>
            </div>
          </div>
          <div className="div3">
            <h3>24小时烟气浓度 </h3>
            <div ref={chartDom7} style={{ width: '100%', height: '300px' }} />
          </div>
        </div>
      </div>
    </div>
  )
}

export default App
